;(function(){
    class Login{
        constructor(){
            this.user=document.querySelector('#user');
            this.pass=document.querySelector('#pass');
            this.submit=document.querySelector('#loginsubmit');
            this.msg=document.querySelector('.loginPerfect-data span');
            this.rem=document.getElementById('remember');
            this.addEvent();
        }
        addEvent(){
            var that=this;
            this.submit.onclick=function(){
                that.u=that.user.value;
                that.p=that.pass.value;
                that.setUser();
            }
        }
        setUser(){
            this.userMsg=localStorage.getItem("userMsg") ? JSON.parse(localStorage.getItem('userMsg')) : [];
            let i=0;
            let res=this.userMsg.some((val,idx)=>{
                i=idx;
                return val.user===this.u;
            })
            if(res){
                if(this.userMsg[i].pass===this.p){
                    this.msg.innerHTML = "登录成功,3秒后跳转到首页";
                    this.userMsg[i].onoff=1;
                    setTimeout(()=>{
                        location.href='http://localhost/blShop-gulp/src/index.html';
                    },3000);
                }else{
                    this.msg.innerHTML = "用户名密码不符，请重新输入";
                }
            }else{
                this.msg.innerHTML = "用户不存在，请去<a href='http://localhost/blShop-gulp/src/register.html'>注册</a>";
            }
            if(this.rem.checked){
                localStorage.setItem('userMsg',JSON.stringify(this.userMsg));
            }
        }
    }
    new Login();
})();